#include "dialog.h"
#include "ui_dialog.h"
#include <QGridLayout>

const static double PI = 3.1416;

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    label_1 = new QLabel(this);
    label_1->setText(tr("请输入圆的半径："));
    label_2 = new QLabel(this);
    lineEdit = new QLineEdit(this);
    button = new QPushButton(this);
    button->setText(tr("计算"));
    QGridLayout * mainLayout = new QGridLayout(this);
    mainLayout->addWidget(label_1, 0, 0);
    mainLayout->addWidget(lineEdit, 0, 1);
    mainLayout->addWidget(label_2, 1, 0);
    mainLayout->addWidget(button, 1, 1);

    connect(button, SIGNAL(clicked()), this, SLOT(showArea()));
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::showArea()
{
    bool ok;
    QString tempStr;
    QString valueStr = lineEdit->text();
    int valueInt = valueStr.toInt(&ok);
    double area = PI * valueInt * valueInt;
    label_2->setText(tempStr.setNum(area));
}
